package liuds.music;

import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ScrollView;
import android.support.design.widget.NavigationView;
import android.widget.TextView;

import me.imid.swipebacklayout.lib.SwipeBackLayout;


/**
 * Created by Administrator on 2018/3/26.
 */

public class BaseActivity extends SwipeBackActivity {

    private View rootView;
    protected Toolbar toolbar;
    private FrameLayout contentView;
    protected SwipeBackLayout swipeBackLayout;

    protected ViewStub loadView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initRootView();

        App.addActivity(this);

        swipeBackLayout = getSwipeBackLayout();
        // 设置滑动方向，可设置EDGE_LEFT, EDGE_RIGHT, EDGE_ALL, EDGE_BOTTOM
        swipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);
        // 滑动退出的效果只能从边界滑动才有效果，如果要扩大touch的范围，可以调用这个方法
//        App.log(App.screenWidth+"width");
//        mSwipeBackLayout.setEdgeSize(200);
        // 可以调用该方法，设置是否允许滑动退出
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
            setSwipeBackEnable(true);
        }else{
            setSwipeBackEnable(false);
        }
    }

    private void initRootView() {
        rootView = getLayoutInflater().inflate(R.layout.activity_base,null);

        toolbar = rootView.findViewById(R.id.toolbar);
        toolbar.setTitleTextColor(Color.WHITE);
        setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(R.drawable.back);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        contentView = rootView.findViewById(R.id.contentView);
    }

    @Override
    public void setContentView(int layoutResID) {
        getLayoutInflater().inflate(layoutResID,contentView);
        super.setContentView(rootView);
    }

    @Override
    public void setContentView(View view) {
        contentView.addView(view);
        super.setContentView(rootView);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

}
